package com.xaaef.k8sdemo.provider;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * <p>
 * </p>
 *
 * @author WangChenChen
 * @version 1.1
 * @date 2023/5/4 15:12
 */


@RequestMapping
@RestController
@SpringBootApplication
public class ProviderApplication {


    public static void main(String[] args) {
        SpringApplication.run(ProviderApplication.class, args);
    }


    @GetMapping()
    public String index() {
        return StrUtil.format("provider ===> : {}", IdUtil.fastSimpleUUID());
    }


    @GetMapping("hello")
    public String hello(@RequestParam("name") String name) throws UnknownHostException {
        if ("tom".equals(name)) {
            throw new RuntimeException("名称不能为tom");
        }
        var hostAddress = InetAddress.getLocalHost().getHostAddress();
        return StrUtil.format("provider -> {} : hello {}", hostAddress, name);
    }


}
